package edu.gatech.oad;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.EditText;
import android.widget.TextView;

public class ItemActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_item);
		
		Bundle extras = getIntent().getExtras();	
		final TextView itemDesc = (TextView) findViewById(R.id.itemDescA);
		final TextView itemLoc = (TextView) findViewById(R.id.itemLocationA);
		final TextView itemCat = (TextView) findViewById(R.id.itemCategoryA);
		final TextView itemDate = (TextView) findViewById(R.id.itemDateA);
		final TextView itemStatus = (TextView) findViewById(R.id.itemStatusA);
		
		final TextView matchDesc = (TextView) findViewById(R.id.matchDescA);
		final TextView matchLoc = (TextView) findViewById(R.id.matchLocationA);
		final TextView matchCat = (TextView) findViewById(R.id.matchCategoryA);
		final TextView matchDate = (TextView) findViewById(R.id.matchDateA);
		final TextView matchStatus = (TextView) findViewById(R.id.matchStatusA);
		
		DataBaseHelper dbHelper = new DataBaseHelper(getApplicationContext());
		try {
			dbHelper.createDataBase();
			dbHelper.openDataBase();
		} catch (Exception ioe) {
			throw new Error("Unable to create database");
		}
		
		String itemDataString = null;
		String[] itemData;
		if(extras != null)
		{
			itemDataString = extras.getString("data");
			System.out.println(itemDataString);
		}
		if(itemDataString != null)
		{
			itemData= itemDataString.split(";");
			Item newItem = new Item(itemData[0], itemData[1], itemData[2], itemData[3], itemData[4], "whatevs");
			itemDesc.setText(newItem.getItemDescription());
			itemLoc.setText(newItem.getLocation());
			itemCat.setText(newItem.getCategory());
			itemDate.setText(newItem.getDate());
			itemStatus.setText(newItem.getStatus());
			
			Item match = dbHelper.bestMatch(newItem);
			matchDesc.setText(match.getItemDescription());
			matchLoc.setText(match.getLocation());
			matchCat.setText(match.getCategory());
			matchDate.setText(match.getDate());
			matchStatus.setText(match.getStatus());
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.item, menu);
		
		 
		return true;
	}

}
